package com.aigou.admin.controller;


import com.aigou.admin.entity.ResponseEntity;
import com.aigou.admin.service.Product_typeService;
import com.aigou.admin.entity.*;
import com.aigou.admin.service.impl.Product_typeServiceImpl;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/productType")
public class Product_typeController extends BaseServlet{
    private Product_typeService service=new Product_typeServiceImpl();

    public void save(HttpServletRequest req, HttpServletResponse resp) throws Exception{
        String id = req.getParameter("id");
        String product_type_name = req.getParameter("product_type_name");
        String product_type_desc = req.getParameter("product_type_desc");
        String product_type_icon = req.getParameter("product_type_icon");

        Product_type product_type = new Product_type(id,product_type_name,product_type_desc,product_type_icon);
        Boolean rs = service.insert(product_type);
        ResponseEntity.ok(resp,rs);
    }

    public void update(HttpServletRequest req, HttpServletResponse resp) throws Exception{
        String id = req.getParameter("id");
        String product_type_name = req.getParameter("product_type_name");
        String product_type_desc = req.getParameter("product_type_desc");
        String product_type_icon = req.getParameter("product_type_icon");

        Product_type product_type = new Product_type(id,product_type_name,product_type_desc,product_type_icon);
        Boolean rs = service.update(product_type);
        ResponseEntity.ok(resp,rs);
    }

    public void findAll(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        List<Product_type> list = service.selectAll();
        ResponseEntity.ok(resp,list);
    }


    public void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String id = req.getParameter("id");
        Boolean rs = service.delete(id);
        //查询用户
        ResponseEntity.ok(resp,rs);
    }

    //分页查询
    public void page(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String current = req.getParameter("current");
        String pageSize = req.getParameter("pageSize");
        //查询用户
        PageEntity<Product_type> page = service.selectPage(Integer.parseInt(current), Integer.parseInt(pageSize));
        ResponseEntity.ok(resp,page);
    }
}
